package com.tanhua.server.controller;




import com.tanhua.server.service.FreezeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/management/manage")
public class FreezeController {
    @Autowired
    private FreezeService freezeService;

    /**
     * 用户冻结
     * @param param
     * @return
     */
    @PostMapping("/users/freeze")
    public ResponseEntity<String>queryFreeze(@RequestBody Map<String,Object>param){
        try {
            String message=freezeService.queryFreeze(param);
            if (message != null) {
                return ResponseEntity.ok(message);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }

    /**
     * 用户解冻
     * @param param
     * @return
     */
    @PostMapping("/users/unfreeze")
    public ResponseEntity<String>queryUnFreeze(@RequestBody Map<String,Object>param){
        Integer userId= (Integer) param.get("userId");
        String reasonsForThawing= (String) param.get("frozenRemarks");
        try {
            String message=freezeService.queryUnFreeze(userId,reasonsForThawing);
            if (message!=null){
                return ResponseEntity.ok(message);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }
}
